package com.gyms.view.bottomview;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Window;
import android.view.WindowManager;

import com.gyms.R;


/**
 * 底部弹出框基础对话框
 */
public abstract class BaseBottomDialog extends Dialog {
    protected Context context;
    protected int animationStyle;
    private boolean isTop = false;

    public BaseBottomDialog(Context context, int animationStyle) {
        super(context, R.style.BottomViewTheme_Defalut);
        this.context = context;
        this.animationStyle = animationStyle;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutResId());
        init();
        initView();
    }

    protected abstract int getLayoutResId();
    protected abstract void initView();
    private void init() {
        this.setCanceledOnTouchOutside(true);
        Window wm = this.getWindow();
        WindowManager m = wm.getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = wm.getAttributes();
        p.width = d.getWidth() * 1;
        if (this.isTop) {
            p.gravity = 48;
        } else {
            p.gravity = 80;
        }
        if (this.animationStyle != 0) {
            this.getWindow().setWindowAnimations(this.animationStyle);
        }
    }
}
